<template>
  <div  class="auto">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <label for="f_tablebase" class=" col-sm-2 control-label">表底数:</label>
        <div class="col-sm-2">
          <input class="form-control" type="number" v-model="model.f_tablebase" @blur='tablebaseChange()' placeholder="表底数" :disabled="disabled">
        </div>
      </form>
      <div class="col-sm-4" style="margin-left:8%" v-if="!message">
        <button class="btn btn-success" @click="confirm()"  :disabled='!$v.valid'>确&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;认</button>
        <button class="btn btn-default" @click="clean()" style="width:80px;margin-left:20px;">取&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;消</button>
      </div>
    </validator>
  </div>
</template>
<script>
/**
*换表管理
*处理表类型为气量卡表的旧表信息
*/
export default {
  data () {
    return {
      model: {},
      isdecimal: '否',
      disabled: false
    }
  },
  props: ['row', 'message'],
  ready () {
    this.isdecimal = this.row.f_isdecimal
  },
  methods: {
    confirm () {
      if (this.model.f_tablebase > this.row.f_meter_base) {
        this.$ChangeMeterService.changeMeter(this.model, this.row).then((res) => {
          res.data.errorType = 'exceeduse'
          this.$dispatch('firstsuccess', 'hand', res.data)
          this.disabled = true
        }).catch((error) => {
          this.$error(error)
          this.$dispatch('error')
        })
      } else {
        this.row.f_newremanent_gas = (this.row.f_remanent_gas - 0) + (this.row.f_meter_base - this.model.f_tablebase)
        this.row.f_tablebase = this.model.f_tablebase
        this.$dispatch('firstsuccess', 'nohand')
      }
    },
    clean () {
      this.$dispatch('clean', this.row)
    },
    tablebaseChange () {
      if (this.isdecimal === '是') {
        this.model.f_tablebase = (this.model.f_tablebase - 0).toFixed(2)
      } else {
        this.model.f_tablebase = (this.model.f_tablebase - 0).toFixed(0)
      }
    }
  }
}
</script>
